package com.example.regex;

import com.example.blackredtree.RedBlackTree;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

public class RegexExample {

    private static final Logger logger = LoggerFactory.getLogger(RedBlackTree.class);

    public static void main(String[] args) {
        // 待匹配的文本
        String text = "哥哥 你 佳我 q聊   3823035316 啊啊啊";

        // 匹配模式
        Set<String> forbiddenWords = new HashSet<>();
        forbiddenWords.add(".*佳\\s*我\\s*Q\\s*聊\\s*3823035316.*");
        forbiddenWords.add(".*佳\\s*我\\s*Q\\s*聊.*");

        forbiddenWords.stream()
                .filter(word -> {
                    boolean matches = Pattern.compile(word, Pattern.CASE_INSENSITIVE).matcher(text).find();
                    logger.info("Checking text '{}' for forbidden word '{}': {}", text, word, matches);
                    return matches;
                })
                .findFirst()
                .ifPresent(matchedWord -> {
                    logger.info(String.format("Message contains forbidden word: %s, text: %s", matchedWord, text));
                });
    }
}

